
#include <Measurement.h>

#define BASE_UNIT 1

Measurement::Measurement(const int amount, const Unit& unit)
    : amount(amount),
      unit(unit)
{
}

bool Measurement::operator==(const Measurement& other) const
{
    if(isSameUnitType(other))
    {
        return calcWithAmountAndUnit() == other.calcWithAmountAndUnit();
    }

    return false;
}

bool Measurement::operator!=(const Measurement& other) const
{
    return !(*this == other);
}

Measurement Measurement::operator+(const Measurement& other) const
{
    if(isSameUnitType(other))
    {
        int valueInBaseUnit = calcWithAmountAndUnit() + other.calcWithAmountAndUnit();
        return Measurement(valueInBaseUnit, other.unit.getBaseUnit());
    }
    else
    {
        return Measurement(INVALID_OPERATION, other.unit);
    }
}

string Measurement::toString(const int printModel) const
{
    return unit.toString(printModel, calcWithAmountAndUnit());
}

int Measurement::calcWithAmountAndUnit() const
{
    return amount * unit.getValueOfUnit();
}

bool Measurement::isSameUnitType(const Measurement& other) const
{
    if(this->unit.isSameUnitType(other.unit))
        return true;
    return false;
}




